//
//  LXStoreViewCell.m
//  LvXi_newVersion
//
//  Created by 诸葛孔明 on 16/9/7.
//  Copyright © 2016年 SJT. All rights reserved.
//............................................................................................//
//...........................................首页-侧滑-收藏cell..........................................//
//............................................................................................//

#import "LXStoreViewCell.h"
#import "LXShopCartController.h"

@implementation LXStoreViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        UIImageView *iconImageView = [[UIImageView alloc] init];
        [self addSubview:iconImageView];
        self.iconImageView = iconImageView;
        
        UILabel *nameLabel = [[UILabel alloc] init];
        nameLabel.font = [UIFont systemFontOfSize:15];
        nameLabel.textColor = HexColor(@"#222222");
        nameLabel.numberOfLines = 1;
        [self addSubview:nameLabel];
        self.nameLabel = nameLabel;
        
        UILabel *priceLabel = [[UILabel alloc] init];
        priceLabel.font = [UIFont systemFontOfSize:12];
        priceLabel.textColor = HexColor(@"#F0A228");
        [self addSubview:priceLabel];
        self.priceLabel = priceLabel;
        
        UIButton *shoppingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [shoppingBtn addTarget:self action:@selector(shoppingBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [shoppingBtn setBackgroundImage:[UIImage imageNamed:@"Shopping-cart-is-not-selected"] forState:UIControlStateNormal];
        [shoppingBtn setBackgroundImage:[UIImage imageNamed:@"Shopping-cart-is-selected"] forState:UIControlStateHighlighted];
        [self addSubview:shoppingBtn];
        self.shoppingBtn = shoppingBtn;
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.iconImageView.x = MineRatio(10);
    self.iconImageView.y = MineRatio(15);
    self.iconImageView.width = MineRatio(75);
    self.iconImageView.height = MineRatio(75);
    
    self.shoppingBtn.width = MineRatio(80);
    self.shoppingBtn.height = MineRatio(36);
    self.shoppingBtn.x = self.width - self.shoppingBtn.width - MineRatio(10);
    self.shoppingBtn.botton = self.iconImageView.botton;
    
    self.nameLabel.width = self.width-self.iconImageView.width-20;
    self.nameLabel.height = self.height-self.shoppingBtn.top;
    self.nameLabel.x = self.iconImageView.right + MineRatio(10);
    self.nameLabel.y = self.iconImageView.y;
    
    self.priceLabel.width = [self.priceLabel.text sizeInAre:MaxSize font:self.priceLabel.font].width;
    self.priceLabel.height = [self.priceLabel.text sizeInAre:MaxSize font:self.priceLabel.font].height;
    self.priceLabel.x = self.nameLabel.x;
    self.priceLabel.botton = self.shoppingBtn.botton;
    
}

- (void)shoppingBtnClick
{
    LXShopCartController *shopCarVc = [[LXShopCartController alloc] init];
    [[self getCurrentVC].navigationController pushViewController:shopCarVc animated:YES];
}

- (void)setFrame:(CGRect)frame
{
    frame.origin.x += 10;
    frame.size.width = ScreenWidth - 20;
    [super setFrame:frame];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    
}

@end
